package minishell.cmdlet.buildin;

import java.util.ArrayList;
import java.util.List;

import minishell.cmdlet.AbstractCmdlet;
import minishell.cmdlet.Cmdlet;
import minishell.object.IObject;
import minishell.object.ListUtilities;
import minishell.object.StringObject;
import minishell.util.BuildinCmdlets;

public class ManCmdlet extends AbstractCmdlet
{
	public List<IObject> excute( String command )
	{
		String name = command;
		if( false == BuildinCmdlets.isBuildinCmdlet( name ) )
			return ListUtilities.stringList( '\'' + name + "' is not a buildin cmdlet" );
		//===========================================
		Cmdlet cmd = BuildinCmdlets.getCmdlet( name );
		if( null == cmd )
			return ListUtilities.stringList( "Cann't get '" + name + "' instance" );
		//=============================================
		ArrayList<IObject> list = new ArrayList<IObject>();
		list.add( new StringObject( "NAME:" ) );
		list.add( new StringObject( "\t" + cmd.getName() ) );
		list.add( new StringObject( "USAGE:" ) );
		list.add( new StringObject( "\t" + cmd.getUsage() ) );
		list.add( new StringObject( "DESCRIPTION:" ) );
		list.add( new StringObject( "\t" + cmd.getDescription() ) );
		return list;
	}
}
